<template>
  <div class="progress-circle">
    <!-- viewbo代表了视口的宽度和位置，100对应了圆的直径100,刚好填满,所以外部可以传任何半径 -->
    <svg
      viewBox="0 0 100 100"
      version="1.1"
      xmlns="http://www.w3.org/2000/svg"
      :width="radius"
      :height="radius"
    >
      <!-- 内层的圆： -->
      <!-- r代表半径，cx,cy代表圆心坐标: -->
      <circle class="progress-background" r="50" cx="50" cy="50" fill="transparent" />
      <!-- 外层的圆： -->
      <!-- stroke-dasharray为描边：stroke-dashoffset为描边的偏移 -->
      <circle
        class="progress-bar"
        r="50"
        cx="50"
        cy="50"
        fill="transparent"
        :stroke-dasharray="dashArray"
        :stroke-dashoffset="dashoffset"
      />
    </svg>
    <slot></slot>
  </div>
</template>

<script>
export default {
  props: {
    radius: {
      type: Number,
      default: 100
    },
    percent: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      // 周长：
      dashArray: parseInt(Math.PI * (50 * 2))
    };
  },
  computed: {
    dashoffset() {
      // stroke-dasharray是圆的周长，当dashoffset为314的时候相当于百分0,当dashoffset为0的时候相当于percent百分百
      return (1 - this.percent) * this.dashArray;
    }
  }
};
</script>

<style lang="less" scoped>
.progress-circle {
  position: relative;
  height: 30px;
  circle {
    stroke-width: 8px;
    transform-origin: center;
    &.progress-background {
      transform: scale(0.9);
      stroke: @color-theme-d;
    }
    &.progress-bar {
      transform: scale(0.9) rotate(-90deg);
      stroke: @color-theme;
    }
  }
}
</style>